package com.dehui.traders.ui.usercenter;

import android.app.Activity;
import android.content.Intent;
import android.support.v4.content.ContextCompat;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;

import com.dehui.traders.BR;
import com.dehui.traders.R;
import com.dehui.traders.databinding.ActivityEditTextBinding;
import com.dehui.traders.ui.base.AppActvity;


public class EditTextActivity extends AppActvity<ActivityEditTextBinding,EditTextViewModel> {

    private static final String IntentKey_Type = "IntentKey_Type";
    private static final String IntentKey_Content = "IntentKey_Content";
    public static final int Type_NickName = 1;
    public static final int Type_Phone = 2;
    public static final int Type_Area = 3;
    private int mType;

    public static void start(Activity activity,int type,String content){
        Intent intent = new Intent(activity,EditTextActivity.class);
        intent.putExtra(IntentKey_Type,type);
        intent.putExtra(IntentKey_Content,content);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        activity.startActivity(intent);
    }

    @Override
    public int initContentView() {
        return R.layout.activity_edit_text;
    }

    @Override
    public int initVariableId() {
        return BR.viewModel;
    }

    @Override
    public EditTextViewModel initViewModel() {
        return new EditTextViewModel(this,this);
    }

    @Override
    public void initData() {
        super.initData();
        mType = getIntent().getIntExtra(IntentKey_Type, 0);
        switch (mType){
            case Type_NickName:
                initToolbar("账户信息","用户名");
                binding.editText.setHint("请输入用户名");
                break;
            case Type_Phone:
                initToolbar("账户信息","手机号");
                binding.editText.setHint("请输入手机号");
                break;
            case Type_Area:
                initToolbar("账户信息","常用地址");
                binding.editText.setHint("请输入常用地址");
                break;
        }

        binding.editText.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                String msg = s.toString();
                if (TextUtils.isEmpty(msg)){
                    binding.tvComplete.setEnabled(false);
                    binding.tvComplete.setTextColor(ContextCompat.getColor(EditTextActivity.this,R.color.text_gray));
                }else{
                    binding.tvComplete.setEnabled(true);
                    binding.tvComplete.setTextColor(ContextCompat.getColor(EditTextActivity.this,R.color.white));
                }
            }

            @Override
            public void afterTextChanged(Editable s) {

            }
        });

        String content = getIntent().getStringExtra(IntentKey_Content);
        viewModel.setEditextText(content);

    }

    public int getmType() {
        return mType;
    }
}
